class Solution
{
public:
    double myPow(double x, int n)
    {
        bool negative = false;
        long long nn = n;
        if (nn < 0)
        {
            nn = -nn;
            negative = true;
        }
        double result = 1.0;
        double exp = x;
        while (nn)
        {
            if (nn & 1)
            {
                result *= x;
            }
            x *= x;
            nn = nn >> 1;
        }
        if (negative)
        {
            result = 1.0 / result;
        }
        return result;
    }
};